package org.canaan.auth2.handler;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;


public class LoginStatusHandler implements AuthenticationSuccessHandler, AuthenticationFailureHandler {
	private final Logger logger = LoggerFactory.getLogger(LoginStatusHandler.class);
	
	
	/**
	 * 1.用户登录成功处理：返回登录成功标识，并发送系统初始化使用的基础数据
	 * 2.记录登录日志
	 */
	@Override
	public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
			Authentication authentication) throws IOException, ServletException {
		logger.debug("用户登录成功");
		
		
		
		response.setCharacterEncoding("utf-8");
		Writer writer = response.getWriter();
	
	}
	
	

	@Override
	public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
			AuthenticationException exception) throws IOException, ServletException {
		logger.debug("登录失败！");
	}
	

}

